Home:ALL Converter>Python -> TypeError: unsupported operand type(s) for ^

Python -> TypeError: unsupported operand type(s) for ^

Ask Time:2017-11-14T21:47:07         Author:Adam Perliński

Json Formatter

I am struggling with Python code. I want to do this equation.

This my code:

fs= 5000
T=np.linspace(0,2.2,fs)
n=np.arange(fs*2.2)
u=[]
for x in T:
    if x < 0.2:
        u.append(x * np.sin(34*np.pi*n/fs))
    if (x >= 0.2 and x < 0.8):
        u.append(1/x * np.log10(x+1))
    if x >= 0.8 and x < 1.4:
        u.append((x^2 + 1) * np.sin(12*np.pi*n/fs))
    if x >= 1.4:
        u.append(np.sin(20*np.pi*n/fs + x/3))

And python returns:

  File "D:/Semestr V/Podstawy Transmisji Danych/labki-ZAD3.py", line 20, in <module>
    u.append((x^2 + 1) * np.sin(12*np.pi*n/fs))

TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'int'

Author:Adam Perliński,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47287462/python-typeerror-unsupported-operand-types-for
timgeb :

The power operator is **, ^ is bitwise XOR.",
2017-11-14T13:48:57
yy